<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/vue/healthmobile.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }


    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约订单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">

        <el-form :inline="true" :model="formInline" class="demo-form-inline">

            <!--开始日期-->
            <el-date-picker
                    v-model="pagination.starttime"
                    type="date"
                    placeholder="开始日期">
            </el-date-picker>

            <!--结束的日期-->
            <el-date-picker
                    v-model="pagination.endtime"
                    type="date"
                    placeholder="结束日期">
            </el-date-picker>

            <!---->
            <el-form-item>
                <el-select v-model="pagination.orderType" placeholder="预约类型">
                    <el-option label="微信预约" value="微信预约"></el-option>
                    <el-option label="电话预约" value="电话预约"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-select v-model="pagination.orderStatus" placeholder="到诊状态">
                    <el-option label="未到诊" value="未到诊"></el-option>
                    <el-option label="已到诊" value="已到诊"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-input v-model="pagination.telename" placeholder="会员姓名/手机号"></el-input>
            </el-form-item>

            <!--代办-->
            <el-form-item>
                <el-button @click="findPage()">查询</el-button>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmit()">预约</el-button>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onClear">清除</el-button>
            </el-form-item>

        </el-form>


        <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

            <el-table-column type="index" align="center" label="序号"></el-table-column>
            <el-table-column prop="membername" label="会员姓名" align="center"></el-table-column>

            <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>

            <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>

            <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>


            <el-table-column label="预约状态" align="center">
                <template slot-scope="scope">
                    <span @click="kk(scope.row)">{{scope.row.value == true ? '已到诊' : '未到诊' }}
                         <el-switch
                                 v-model="scope.row.value"
                                 active-color="#13ce66"

                                 inactive-color="#ff4949">

                    </el-switch>
                    </span>


                </template>
            </el-table-column>


            <el-table-column prop="setmealname" label="套餐名称" align="center"></el-table-column>


            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button type="primary" size="mini" @click="compile(scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="dele(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination-container">
            <el-pagination
                    class="pagiantion"
                    @current-change="handleCurrentChange"
                    :current-page="pagination.currentPage"
                    :page-size="pagination.pageSize"
                    layout="total, prev, pager, next, jumper"
                    :total="pagination.total">
            </el-pagination>
        </div>
        <!-- 新增标签弹层 -->
        <div class="add-form">
            <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                <template>
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">


                                        <el-form-item label="手机号码" required="true">
                                            <el-input @blur="checkTele" v-model="formData.phoneNumber"
                                                      placeholder="选择输入手机号"/>
                                        </el-form-item>

                                    </el-col>
                                    <!--这里改成预约日期-->
                                    <el-col :span="12">
                                        &nbsp;&nbsp;&nbsp;预约日期
                                        <el-date-picker
                                                v-model="formData.orderDate"
                                                type="date"
                                                placeholder="选择日期">
                                        </el-date-picker>
                                    </el-col>
                                </el-row>

                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="姓名">
                                            <el-input v-model="formData.name" placeholder="请输入姓名"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="套餐信息" name="second">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>套餐编码</th>
                                        <th>套餐名称</th>
                                        <th>套餐说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="c in tableData">
                                        <td>
                                            <input :id="c.id" v-model="checkgroupIds" type="checkbox" :value="c.id">
                                        </td>
                                        <td><label :for="c.id">{{c.code}}</label></td>
                                        <td><label :for="c.id">{{c.name}}</label></td>
                                        <td><label :for="c.id">{{c.remark}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </template>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取消</el-button>
                    <el-button type="primary" @click="save()">确定</el-button>
                </div>
            </el-dialog>
        </div>
        <!--编辑-->
        <div class="add-form">
            <el-dialog title="编辑预约" :visible.sync="dialogFormVisibles">
                <template>
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form label-position="right" label-width="100px" :rules="rules">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="姓名">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <!--这里改成预约日期-->
                                    <el-col :span="12">
                                        &nbsp;&nbsp;&nbsp;预约日期
                                        <el-date-picker
                                                v-model="formData.orderDate"
                                                type="date"
                                                placeholder="选择日期">
                                        </el-date-picker>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <!--有下拉框-->
                                    <el-col :span="12">
                                        <el-form-item label="预约类型">
                                            <el-select v-model="formData.orderType">
                                                <el-option label="微信预约" value="微信预约"></el-option>
                                                <el-option label="电话预约" value="电话预约"></el-option>
                                            </el-select>
                                        </el-form-item>


                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预约状态">

                                            <el-select v-model="formData.orderStatus">
                                                <el-option label="未到诊" value="未到诊"></el-option>
                                                <el-option label="已到诊" value="已到诊"></el-option>

                                            </el-select>

                                        </el-form-item>
                                    </el-col>
                                </el-row>

                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="套餐信息" name="second">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>套餐编码</th>
                                        <th>套餐名称</th>
                                        <th>套餐说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="c in tableData">
                                        <td>
                                            <input :id="c.id" v-model="checkgroupIds" type="checkbox" :value="c.id">
                                        </td>
                                        <td><label :for="c.id">{{c.code}}</label></td>
                                        <td><label :for="c.id">{{c.name}}</label></td>
                                        <td><label :for="c.id">{{c.remark}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </template>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisibles = false">取消</el-button>
                    <el-button type="primary" @click="editor()">确定</el-button>
                </div>
            </el-dialog>
        </div>

    </div>
</div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {

            /*表单*/
            formInline: {
                user: '',
                region: ''
            },
            autoUpload: true,//自动上传
            imageUrl: null,//模型数据，用于上传图片完成后图片预览
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 0,
                queryString: null,
                telename: null,
                orderType: null,
                orderStatus: null,
                starttime: null,
                endtime: null
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//添加表单窗口中套餐组列表数据
            checkgroupIds: [],//添加表单窗口中检查组复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisibles: false, //控制编辑窗口显示/隐藏
            rules: {//校验规则
                phoneNumber: [{required: true, message: '手机号码为必填项', trigger: 'blur'}]},

        },
        created() {
            this.findPage();
        },
        methods: {
            //状态修改
            kk(row) {
                axios.post('/subscribe/alterthestate.do', row).then(resp => {
                    if (resp.data.flag) {
                        this.$message({
                            type:'success',
                            message:resp.data.message
                        });
                    } else {
                        this.$message(resp.data.message);
                    }
                })
            },


            //清楚查询框
            onClear() {
                this.pagination.telename = '';
                this.pagination.orderStatus = '';
                this.pagination.starttime = '';
                this.pagination.endtime = '';
                this.pagination.orderType = '';
                this.findPage();
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //分页查询
            findPage() {
                //第几页一页多少数量 查询的内容传入后台
                axios.post('/subscribe/findPage.do', this.pagination).then(resp => {
                    this.pagination.total = resp.data.total;
                    this.dataList = resp.data.rows
                })
            },

            resetForm() {
                //情况表单
                this.formData = {};
                //清空右侧套餐
                this.checkgroupIds = [];
            },

            //手机号校验
            checkTele() {
                if (!checkTelephone(this.formData.phoneNumber)) {
                    this.$message.error("请输入正确的手机号");
                    return false;
                }
            },

            //弹出预约 添加窗口
            onSubmit() {
                this.activeName = 'first';
                this.resetForm();
                this.dialogFormVisible = true;
                //回显
                this.setmealecho();

            },
            /*套餐数据的回显全部*/
            setmealecho() {
                axios.get('/subscribe/echo.do').then(resp => {
                    if (resp.data.flag) {
                        this.tableData = resp.data.data;
                        console.log(this.formData.orderDate);
                    } else {
                        this.$message(resp.data.message);
                    }

                });
            },
            /*添加保存*/
            save() {
                if (!checkTelephone(this.formData.phoneNumber)) {
                    this.$message.error("请输入正确的手机号");
                    return false;
                } else {
                    axios.post('/subscribe/add.do?id=' + this.checkgroupIds, this.formData).then(resp => {
                        //添加就不需要返回数据了
                        if (resp.data.flag) {
                            //添加成功
                            this.$message({
                                type:'success',
                                message:resp.data.message
                            });
                            this.dialogFormVisible = false;
                            this.findPage();
                        } else {
                            this.$message.error(resp.data.message);
                        }
                    })
                }
            },

            //编辑.回显
            compile(row) {
                this.activeName = 'first';
                this.dialogFormVisibles = true;
                this.formData = {};

                //回显
                //id是会员id
                axios.post('/subscribe/editecho.do?id=' + this.checkgroupIds, row).then(resp => {
                    if (resp.data.flag) {
                        this.formData = resp.data.data
                    } else {
                        this.$message.error(resp.data.message);
                    }

                });


                this.setmealecho();
                //回显套餐
                axios.post('/subscribe/setmealecho.do', row).then(resp => {
                    if (resp.data.flag) {
                        this.checkgroupIds = resp.data.data;
                    } else {
                        this.$message.error(resp.data.message);
                    }

                });

            },

            /*编辑*/
            editor() {
                this.dialogFormVisibles = false;
                axios.post('/subscribe/editor.do?id=' + this.checkgroupIds, this.formData).then(resp => {
                    console.log(this.formData.orderDate);
                    if (resp.data.flag) {
                        this.$message({
                            type:'success',
                            message:resp.data.message
                        });
                        this.findPage();
                    } else {
                        this.$message.error(resp.data.message);
                    }
                })
            },


            /*删除*/
            dele(row) {
                console.log(row);
                this.$confirm("你确定要删除当前数据吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    axios.post('/subscribe/dele.do', row).then(resp => {
                        if (resp.data.flag) {
                            this.$message({
                                type:'success',
                                message:resp.data.message
                            });
                        } else {
                            this.$message.error(resp.data.message);
                        }
                    }).finally(() => {
                        this.findPage();
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作已取消'
                    })
                });
            },
        }
    })
</script>
</html>
